********************************
***File Predicts Polarized Participants***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==0  {
cap cd "E:\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\Balance\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/Balance/"
} 

use 1_clean_data, replace


//List Predictors
global predict female white black hispanic i.agegroup i.educgroup i.workgroup i.democrat ///
	i.voted2016 i.candidate2016 i.pre_immlevel_raw5 i.pre_gun_index_raw5 i.pre_abortion_index_raw5 ///
	i.pre_tax_index_raw5 i.pre_health_index_raw5 i.freq_facebook i.freq_twitter ///
	i.freq_tv i.freq_newspaper i.freq_fox i.freq_msnbc i.freq_breitbart ///
	i.freq_buzzfeed i.freq_nytimes i.fan_obama i.fan_trump i.fan_lebronjames ///
	i.fan_billgates i.fan_ellendegeneres i.fan_taylorswift i.fan_kimkardashian ///
	i.georegion i.born_in_us weather_clickcount i.topissue_type

	

/***************************
//Fail Content Check - Predict for Control Group
***************************
//Can't do a relative measure here - only 0/1, no granular median to split by
//Use both source variables to make more granular)

gen drop_number=numbersurveys>1

gen s=drop_consent | drop_audio | drop_citizen | drop_inconsistent | drop_weather ///
 | drop_us | drop_missing | drop_time | drop_number
gen sample2=s==0
gen failcontent=.

tab treat drop_content if sample2==1

/*
rlasso drop_content $predict if treat!=0 & treat<9 & recruit==0 & sample2==1, robust

gen age55_64=0
replace age55_64=1 if agegroup==5
gen age65_74=0
replace age65_74=1 if agegroup==6
gen age75=0
replace age75=1 if agegroup==7
gen health_notgvt=0 
replace health_notgvt=1 if pre_health_index_raw5==5
gen daily_facebook=0
replace daily_facebook=1 if freq_facebook==3
gen occ_fox=0
replace occ_fox=1 if freq_fox==2
gen daily_nytimes=0
replace daily_nytimes=1 if freq_nytimes==3
gen weekly_breitbart=0
replace weekly_breitbart=1 if freq_breitbart==3


global plasso0 gender_other black age55_64 age65_74 age75 health_notgvt daily_facebook occ_fox daily_nytimes weekly_breitbart

rlasso drop_content $predict if treat!=0 & recruit==1 & sample2==1, robust

gen gender_other=gender==2
gen kardashianfan=fan_kimkardashian==2
gen topissue_health=0
replace topissue_health=1 if topissue_type==4
gen daily_fox=0
replace daily_fox=1 if freq_fox==3

global plasso1 gender_other black age65_74 kardashianfan topissue_health daily_fox
*/

foreach p in 0 1 {

logit drop_content $predict timesurvey beforevote if  treat!=0 & recruit==`p' & (sample2==1 )
	predict f if recruit==`p' & (sample2==1), pr
	replace failcontent=f if recruit==`p' & (sample2==1 )
	drop f
		
}

xtile f=failcontent if sample2==1, nq(200)

gen failcontent_discrete=f>191 & sample2==1
gen samef=failcontent_discrete==drop_contentpost if treat!=0

noisily di "Share of Correct Predictions"
noisily tab samef if drop_content==1 & sample2==1 //33-35% right 
noisily tab samef if failcontent_discrete==1 & sample2==1 //33-35% right 



drop s sample2 failcontent 
*$plasso0 $plasso1

/*********************************************************
***CHANGE SAMPLE DEFINITION TO USE IMPUTED FAILED CHECK
*********************************************************
drop sample 

gen sample=drop_consent==0 & drop_audio==0 & drop_citizen==0 & drop_treat==0 ///
	& drop_us==0 & drop_inconsistent==0 & drop_weather==0 ///
	& failcontent_discrete==0 & drop_time==0 & drop_missing==0 
*/
*/
*********************************
***Predict Polarized***
*********************************

*keep if sample==1

//Belief Outcome
gen high_raw=prob_index_anti>=0.75  if recruit==0 & treat==0 & sample==1
replace high_raw=prob_index_pro>=0.75  if recruit==1 & treat==0 & sample==1

sum prob_index_anti if recruit==0 & treat==0 & sample==1, d
gen rhigh_raw=prob_index_anti>=r(p75) if recruit==0 & treat==0 & sample==1
sum prob_index_pro if recruit==1 & treat==0 & sample==1, d
replace rhigh_raw=prob_index_pro>=r(p75) if recruit==1 & treat==0 & sample==1

gen prob_high=.
gen rprob_high=.
gen high=.
gen rhigh=.

foreach p in 0 1 {

logit high_raw $predict if treat==0 & recruit==`p' & sample==1
	predict phigh if recruit==`p' & sample==1 , pr
	replace prob_high=phigh if recruit==`p' & sample==1
	replace high=prob_high>0.5 if recruit==`p' & sample==1
	drop phigh
logit rhigh_raw $predict if treat==0 & recruit==`p' & sample==1
	predict phigh if recruit==`p' & sample==1 , pr
	replace rprob_high=phigh if recruit==`p' & sample==1
	replace rhigh=rprob_high>0.5 if recruit==`p' & sample==1
	drop phigh
	
}
	
	
***************************
//Right President Perception
***************************
//Can't do a relative measure here - only 0/1, no granular median to split by
//Use both source variables to make more granular)

gen obama_right_exp_raw=(dummy_source_obama==1 ) if treat==4  
gen trump_right_exp_raw=(dummy_source_trump==1 ) if treat==7 
gen obama_right_unexp_raw=(dummy_source_obama==1 ) if treat==8 
gen trump_right_unexp_raw=(dummy_source_trump==1 ) if treat==3 

gen surprise_raw=(dummy_source_obama==0) if treat==4  
replace surprise_raw=(dummy_source_trump==0) if treat==7 
replace surprise_raw=(dummy_source_obama==0) if treat==8 
replace surprise_raw=(dummy_source_trump==0) if treat==3 
replace surprise_raw=(dummy_source_obama==0) if treat==2 
replace surprise_raw=(dummy_source_trump==0) if treat==5 
replace surprise_raw=(dummy_source_obama==0) if treat==6 
replace surprise_raw=(dummy_source_trump==0) if treat==1 

global obama_right_exp 4
global trump_right_exp 7
global obama_right_unexp 8
global trump_right_unexp 3
global obama_right_expx 2
global trump_right_expx 5
global obama_right_unexpx 6
global trump_right_unexpx 1

gen surprise=.

foreach p in 0 1 {

foreach x in obama_right_exp trump_right_exp obama_right_unexp trump_right_unexp {

logit `x'_raw $predict if treat==${`x'} & recruit==`p' & sample==1
	predict `x' if recruit==`p' & sample==1 & (treat==${`x'} | treat==${`x'x}), pr
	replace surprise=1-`x' if recruit==`p' & sample==1 & (treat==${`x'} | treat==${`x'x})
	drop `x'
		
	}
}

gen actor=treat==7 | treat==8 | treat==3 | treat==4
gen surprise_discrete=surprise>0.5 & surprise!=.
gen same=surprise_discrete==surprise_raw if actor==1

noisily di "Share of Correct Predictions"
noisily tab same //79%


******************************
drop actor same surprise_discrete

save 2_clean_data, replace

